/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package main.java.cn.webrx;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

/**
 * <p>Project: jse2204 - Ex9
 * <p>Powered by webrx On 2022-09-23 11:35:12
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex9 {
    public static void main(String[] args) throws Exception {
// 压缩单个文件

        String path = "C:\\Users\\Administrator\\Desktop\\test.txt";
        String zippath = "C:\\Users\\Administrator\\Desktop\\"; // 压缩文件保存路径
        File file = new File(path);
        File zipFile = new File(zippath + "one.zip"); // 给压缩包起名
        InputStream input = new FileInputStream(file);

        ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));

        zipOut.putNextEntry(new ZipEntry("newzipone.txt")); // 给压缩内容文件起名

        zipOut.setComment("i am lyk");
        int temp = 0;
        while ((temp = input.read()) != -1){
            zipOut.write(temp);
        }
        input.close();
        zipOut.close();


    }
}
